
"""
中文错别字纠正接口
"""
import json
from fastapi import Body
from server.api_wrap import async_api_wrapper
from control.control import (
    correct_error,
)
from loguru import logger
from correct.corrector import Corrector

corrector = Corrector()

@async_api_wrapper
async def correct_error_api(
        data: dict = Body(description='错字审查', examples=None)
):
    logger.info(f'错字审查输入: {json.dumps(data, ensure_ascii=False)}')

    try:
        result = correct_error(data)
        response = {'success': True, 'error': None, 'result': result}
    except Exception as e:
        response = {'success': False, 'error': str(e), 'result': []}

    logger.info(f'错字审查结果: {json.dumps(response, ensure_ascii=False)}')
    return response